package com.xuantu.learn.springsession2.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginController {

	@RequestMapping(value= {"login", ""}, method = RequestMethod.GET )
	public String login() {
		return "login";
	}
	
	@RequestMapping(value= {"login"}, method = RequestMethod.POST )
	public String login(HttpServletRequest request) {
		String user = request.getParameter("user");
		request.getSession().setAttribute("USER", user);
		return "redirect:/index";
	}
	
	@RequestMapping(value= {"index"}, method = RequestMethod.GET )
	public String home(HttpServletRequest request) {
		return "index";
	}
}
